//
//  LGAddCustomMedicineView.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/7/24.
//

#import "LGAddCustomMedicineView.h"

@interface LGAddCustomMedicineView()
/**   */
@property (nonatomic , strong)UIImageView *iconView;
/**   */
@property (nonatomic , strong)UIImageView *tipView;

@end

@implementation LGAddCustomMedicineView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)setTitle:(NSString *)title{
    _title = title;
    self.titleLabel.text = title;
}

-(void)setShowTip:(BOOL)showTip{
    _showTip = showTip;
    self.tipView.hidden = !showTip;
    self.actionBtn.hidden = !showTip;
    CGFloat left = (showTip == YES)?0:viewPix(12);
    [self.contentTF mas_updateConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.tipView.mas_left).offset(left);
    }];
}

-(void)setShowStar:(BOOL)showStar{
    _showStar = showStar;
    self.iconView.hidden = !showStar;
    CGFloat left = (showStar == YES)?viewPix(28):viewPix(12);
    [self.titleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(left);
    }];
}

-(void)createSubView{
    self.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.iconView];
    [self addSubview:self.titleLabel];
    [self addSubview:self.contentTF];
    [self addSubview:self.tipView];
    [self addSubview:self.lineView];
    [self addSubview:self.actionBtn];
    [self.iconView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(viewPix(12));
        make.width.height.equalTo(@(viewPix(12)));
        make.centerY.equalTo(self);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(viewPix(12));
        make.centerY.equalTo(self);
        make.width.equalTo(@(70));
    }];
    [self.contentTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel.mas_right).offset(viewPix(10));
        make.right.equalTo(self.tipView.mas_left).offset(0);
        make.centerY.equalTo(self);
    }];
    
    [self.tipView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-viewPix(12));
        make.width.height.equalTo(@(viewPix(12)));
        make.centerY.equalTo(self);
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(viewPix(12));
        make.right.equalTo(self).offset(-viewPix(12));
        make.bottom.equalTo(self);
        make.height.equalTo(@(0.5));
    }];
    [self.actionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.right.equalTo(self);
    }];
}

-(UIImageView *)iconView{
    if(!_iconView){
        _iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"必选项"]];
        _iconView.hidden = YES;
    }
    return _iconView;
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _titleLabel;
}

-(UITextField *)contentTF{
    if(!_contentTF){
        _contentTF = [[UITextField alloc]init];
        _contentTF.tintColor = [UIColor colorWithString:@"#666666"];
        _contentTF.textColor = [UIColor colorWithString:@"#666666"];
        _contentTF.textAlignment = NSTextAlignmentRight;
        _contentTF.keyboardType = UIKeyboardTypeDefault;
        _contentTF.font = LGFont(15);
    }
    return _contentTF;
}

-(UIImageView *)tipView{
    if(!_tipView){
        _tipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTip12"]];
    }
    return _tipView;
}

-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = [UIColor colorWithString:@"#E8E8E8"];
    }
    return _lineView;
}

-(UIButton *)actionBtn{
    if(!_actionBtn){
        _actionBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    }
    return _actionBtn;
}

@end
